package com.lottery.ruok.lottrey.dialog;


import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;

/**
 * 作者：lm
 * <p>
 * 创建日期：2018/8/21$
 * <p>
 * 描述：遗漏下注弹窗
 */
public class YiLouLotteryBuyDialog extends Dialog {
    private Context mcontext;
    private int layoutResID;
    private Callback callback;
    private TextView tv_yi_lou_buy_name, tv_yi_lou_buy_money, tv_yi_lou_buy_quit, tv_yi_lou_buy_sure;

    public YiLouLotteryBuyDialog(@NonNull Context context, int layoutResId, Callback callback) {
        super(context, R.style.dialogNoBg);
        this.mcontext = context;
        this.layoutResID = layoutResId;
        this.callback = callback;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置为居中
        setContentView(layoutResID);
        // 宽度全屏
        WindowManager windowManager = ((Activity) mcontext).getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = display.getWidth() * 4 / 5; // 设置dialog宽度为屏幕的4/5
        getWindow().setAttributes(lp);
        // 点击Dialog外部消失
        setCanceledOnTouchOutside(false);

        //初始化界面控件
        initView();

    }

    public void setDta(String name, String num) {
        tv_yi_lou_buy_name.setText(name);
        tv_yi_lou_buy_money.setText(num);
    }

    private void initView() {
        tv_yi_lou_buy_name = (TextView) findViewById(R.id.tv_yi_lou_buy_name);
        tv_yi_lou_buy_money = (TextView) findViewById(R.id.tv_yi_lou_buy_money);
        tv_yi_lou_buy_quit = (TextView) findViewById(R.id.tv_yi_lou_buy_quit);
        tv_yi_lou_buy_sure = (TextView) findViewById(R.id.tv_yi_lou_buy_sure);
        tv_yi_lou_buy_quit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.callback(1);
            }
        });
        tv_yi_lou_buy_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.callback(2);
            }
        });
    }

    public interface Callback {
        void callback(int data);
    }
}
